package com.singzi.leetcode.jianzhiOffer;

import java.util.Stack;

public class T0009 {
    public static void main(String[] args) {
        CQueue cQueue = new CQueue();
        cQueue.appendTail(3);
        System.out.println(cQueue.deleteHead());
        System.out.println(cQueue.deleteHead());
    }


}
class CQueue {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public CQueue() {

    }

    public void appendTail(int value) {
        if(stack1.isEmpty() && stack2.isEmpty()) stack1.push(value);
        else if(stack1.isEmpty()){
            while (!stack2.isEmpty()){
                stack1.push(stack2.pop());
            }
            stack1.push(value);
        }
        else stack1.push(value);

    }

    public int deleteHead() {
        if(stack1.isEmpty() && stack2.isEmpty()) return -1;
        if(stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            return stack2.pop();
        }
        else return stack2.pop();
    }
}

